/**
 * 
 */
package com.automation.demo.cucumber;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.When;

/**
 * @author David
 *
 */
public class GoogleSearchStepdefs {
	
	private DesiredCapabilities capabillities = DesiredCapabilities.firefox();  
    
	  
    private WebDriver driver; 
	
    
    @Given("^that I go to google$")
    public void I_go_to_google() {
		System.out.println("start the selemium grid");
    	try {
			driver = new RemoteWebDriver(new URL("http://localhost:4000/wd/hub"), capabillities);
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
        driver.get("http://www.google.com");  
        
    }
    
    @When("^I search for \"(.*)\"$")
    public void I_search_for(String item) {
    	System.out.println("Item:"+ item);
	    WebElement search = driver.findElement(By.name("q"));  
	    search.sendKeys(item);  
	    search.submit();  
	    driver.quit();  
    }

}
